﻿#!/usr/bin/python
# -*- coding: UTF-8 -*-

def fil_add_suffix(name, sufadd):
    namelist = name.split(".")
    # 获取后缀
    name_end = namelist[len(namelist) - 1]

    name_des = namelist[0]
    name_des += '.'
    index = 1
    while index < (len(namelist) - 1):
        name_des += namelist[index]
        name_des += '.'
    name_des += sufadd
    name_des += '.'
    name_des += name_end

    return name_des


# def file name make
def file_name_make(m_path, s_path):
    # 统一分割符
    pathm = str.replace(m_path, "\\", "/")
    paths = str.replace(s_path, "\\", "/")

    # 主路径分割
    mlist = str.split(pathm, '/')
    mlist_len = len(mlist)
    if len(mlist[mlist_len-1]) <= 0:
        mlist_len -= 1

    # 打印主路径信息
    # print("mpath = %s , split len= %d" % (pathm, mlist_len))

    # 打印主路径分割内容
    index = 0
    while index < mlist_len:
        # print("%s" % mlist[index])
        index += 1

    # 相对路径前移
    index = 0
    while paths[index] == '.':
        if mlist_len > 1:
            mlist_len -= 1
        index += 1

    # 目标路径创建
    despath = mlist[0]
    index = 1
    while index < mlist_len:
        despath = despath + "/"
        despath = despath + mlist[index]
        index += 1

    index = 0
    while paths[index] == '.':
        index += 1

    pathadd = str.replace(paths, ".", "", index)
    if pathadd[0] == '/':
        despath = despath + pathadd
    else:
        despath = despath + "/"
        despath = despath + pathadd

    # print("des path = %s" % despath)

    return despath

